class Solution {
    int t = 0;
    int method = 0;
    int sum = 0;
    public int findTargetSumWays(int[] nums, int target) {
        int t = target;
        dfs(nums, 0);
        return method;
    }
    public void dfs(int[] nums, int i){
        if(i == nums.length){
            if(sum == t){
                method++;
            }
            return;
        }
        if(i < nums.length){
            sum += nums[i];
            dfs(nums, i + 1);
            // 回溯
            sum -= nums[i];

            sum += (-1 * nums[i]);
            dfs(nums, i + 1);
            // 回溯
            sum -= (-1 * nums[i]);
        }
    }
}